package com.example.list;

import java.util.ArrayList;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

import com.example.list.adapter.PessoaAdapter;
import com.example.list.model.Pessoa;

public class MainActivity extends Activity implements OnItemClickListener {

	private ListView listView;
	private PessoaAdapter adapter;
	private ArrayList<Pessoa> itens;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		listView = (ListView) findViewById(R.id.listView);
		listView.setOnItemClickListener(this);

		createListView();
	}

	private void createListView() {
		itens = new ArrayList<Pessoa>();

		for (int i = 0; i < 10; i++) {
			itens.add(new Pessoa("Cliente do camelo " + i, "Sobrenome "));
		}

		adapter = new PessoaAdapter(this, itens);

		listView.setAdapter(adapter);
		listView.setCacheColorHint(Color.TRANSPARENT);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		Pessoa pessoa = (Pessoa) adapter.getItem(position);

		Toast.makeText(getApplicationContext(),
				pessoa.getNome() + pessoa.getSobrenome(), Toast.LENGTH_SHORT)
				.show();

	}

}
